
package nccloud.web.arap.amortization.action;

import nc.itf.pubapp.pub.smart.IBillQueryService;
import nc.vo.arap.amortization.AggAmortizationVO;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.model.entity.bill.IBill;
import nccloud.framework.core.exception.ExceptionUtils;
import nccloud.framework.core.json.IJson;
import nccloud.framework.service.ServiceLocator;
import nccloud.framework.web.action.itf.ICommonAction;
import nccloud.framework.web.container.IRequest;
import nccloud.framework.web.json.JsonFactory;
import nccloud.framework.web.ui.pattern.extbillcard.ExtBillCard;
import nccloud.framework.web.ui.pattern.extbillcard.ExtBillCardOperator;
import nccloud.web.arap.amortization.action.base.QueryInfo;

/**
* @description 卡片查询
* @version ncc1.0 通用查询卡片类，无需修改
**/
public class QueryCardAction implements ICommonAction {

    @Override
    public Object doAction(IRequest request) {
        try {
            String str = request.read();
            IJson json = JsonFactory.create();
            QueryInfo info = json.fromJson(str, QueryInfo.class);
            // 查询Bill
            IBill[] bills = this.queryBill(info.getPks());
            // 转换
            ExtBillCardOperator operator = new ExtBillCardOperator(info.getPagecode());
            ExtBillCard retcard = operator.toCard(bills[0]);
            return retcard;
        } catch (Exception e) {
            ExceptionUtils.wrapException(e);
        }
        return null;
    }

    public IBill[] queryBill(String[] ids) throws BusinessException {
        nc.vo.arap.amortization.AggAmortizationVO aggVO = ServiceLocator.find(IBillQueryService.class).querySingleBillByPk(nc.vo.arap.amortization.AggAmortizationVO.class, ids[0]);
        return aggVO == null ? null : new nc.vo.arap.amortization.AggAmortizationVO[] { aggVO };
    }

}
